/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package util;

import java.io.File;
import javax.swing.filechooser.FileSystemView;

/**
 *
 * @author Quân
 */
public class OShandler {

    private File _defaultFolder = null;
    private File _appData = null;
    private String OS = System.getProperty("os.name").toLowerCase();
    private static OShandler instance = null;

    private OShandler() {
    }

    public static OShandler getInstance() {
        if (instance == null) {
            instance = new OShandler();
        }
        return instance;
    }

    public boolean isWindows() {
        return (OS.indexOf("win") >= 0);
    }

    public boolean isMac() {
        return (OS.indexOf("mac") >= 0);
    }

    public boolean isUnix() {
        return (OS.indexOf("nix") >= 0 || OS.indexOf("nux") >= 0 || OS.indexOf("aix") > 0);
    }

    public boolean isSolaris() {
        return (OS.indexOf("sunos") >= 0);
    }

    public boolean isLinux() {
        return (OS.indexOf("linux") >= 0);
    }

    public File getOSDefaultFolder() {
        if (_defaultFolder == null) {
            FileSystemView filesys = FileSystemView.getFileSystemView();
            _defaultFolder = filesys.getDefaultDirectory();
        }
        return _defaultFolder;
    }

    public File getAppDataFolder() {
        if (_appData == null) {
            if (isUnix()) {
            } else if (isWindows()) {
                _appData = new File(System.getenv("LOCALAPPDATA"));
            } else if (isLinux()) {
                _appData = new File(System.getProperty("user.dir"));
            }
        }
        return _appData;
    }
}
